package com.xqkad.myfile.ui;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.Color;
import android.widget.EditText;
import android.widget.TextView;

public class MyDialog {
    private interface Const1{
        int TextColor = Color.WHITE;
    }
    private MyDialog(){}

    public static AlertDialog showMsgDg(Context context, String msg, String title){
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        if(title!=null)
            builder.setTitle(title);
        builder.setView(createTV(context,msg));
        return builder.show();
    }

    public static AlertDialog showYesOrNoDg(Context context, String msg, final Runnable yesRun){
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setView(createTV(context, msg));
        builder.setPositiveButton(" 是 ", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                if(yesRun!=null)
                    yesRun.run();
            }
        });
        builder.setNegativeButton(" 否 ",null);
        return builder.show();
    }

    public static AlertDialog showEditDg(Context context, String msg, final OnYesEdit yesEdit){
        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        final EditText et = createET(context,msg);
        builder.setView(et);
        builder.setPositiveButton("ok", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                String text = et.getText().toString();
                yesEdit.onYesEdit(text);
            }
        });
        return builder.show();
    }

    private static TextView createTV(Context context, String msg){
        final TextView tv = new TextView(context);
        tv.setTextColor(Const1.TextColor);
        tv.setText(""+msg);
        return tv;
    }

    private static EditText createET(Context context, String msg){
        final EditText et = new EditText(context);
        et.setTextColor(Const1.TextColor);
        et.setText(""+msg);
        return et;
    }

    interface OnYesEdit{
        void onYesEdit(String text);
    }
}
